<template>
  <div>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-form-item label="供应商" prop="supplier_id">
        <el-select :disabled="type=='look'" v-model="form.supplier_id" placeholder="请选择">
          <el-option
            v-for="item in supplierList"
            :key="item.supplier_id"
            :label="item.supplier_name"
            :value="item.supplier_id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="出发地" prop="start_address">
        <el-select
          :disabled="type=='look'"
          v-model="form.start_address"
          debounce
          multiple
          filterable
          remote
          placeholder="请输入关键词"
          :remote-method="remoteMethod"
          :loading="loading"
        >
          <el-option
            v-for="(item, index) in startAdress"
            :key="index"
            :label="item.area_name"
            :value="item.area_name"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="系列" prop="series_id">
        <el-select :disabled="type=='look'" v-model="form.series_id" placeholder="全部">
          <el-option
            v-for="item in seriesList"
            :key="item.series_id"
            :label="item.series_name"
            :value="item.series_id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="线路名称" prop="commodity_name">
        <el-input
          :disabled="type=='look'"
          class="w300"
          placeholder="请输入"
          v-model="form.commodity_name"
          autocomplete="off"
        ></el-input>
      </el-form-item>
      <el-form-item label="轮播图片" prop="commodity_img">
        <upimg :imgs.sync="form.commodity_img" :islook="type=='look'" />
      </el-form-item>
      <el-form-item label="上架状态" prop="commodity_release" >
        <el-radio-group v-model="form.commodity_release" :disabled="type=='look'">
          <el-radio v-for="(item, key) in lineStatus" :key="key" :label="key">{{
            item
          }}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="特色标签" prop="lable_ids">
        <el-checkbox-group v-model="form.lable_ids" :disabled="type=='look'">
          <el-checkbox
            v-for="item in tagList"
            :key="item.lable_id"
            :label="item.lable_id"
            >{{ item.lable_name }}</el-checkbox
          >
        </el-checkbox-group>
      </el-form-item>
      <el-form-item label="产品显示售价" prop="pricing" >
        <el-input
          :disabled="type=='look'"
          class="w300"
          placeholder="请输入"
          v-model="form.pricing"
        ></el-input>
      </el-form-item>
      <el-form-item label="成人成本价" prop="cb_price">
        <el-input
          class="w300"
          placeholder="请输入"
          :value="form.cb_price"
          disabled
        ></el-input>
      </el-form-item>
      <el-form-item label="儿童成本价" prop="child_cb_price">
        <el-input
          class="w300"
          placeholder="请输入"
          :value="form.child_cb_price"
          disabled
        ></el-input>
      </el-form-item>
      <el-form-item label="大交通" prop="jt_sprice">
        <el-input
          class="w300"
          placeholder="请输入"
          :value="form.jt_sprice"
          disabled
        ></el-input>
        <div class="traffic-con mt8">
          <div class="item">
            <el-checkbox :disabled="type=='look'" v-model="form.jt_content" label="1">飞机</el-checkbox>
            <div>
              <el-input
                :disabled="type=='look'"
                size="small"
                placeholder="请输入"
                class="smallw"
                v-model="form.fj_price"
              ></el-input
              >&nbsp;元
            </div>
          </div>
          <div class="item">
            <el-checkbox :disabled="type=='look'" v-model="form.jt_content" label="2">动车</el-checkbox>
            <div>
              <el-input
                :disabled="type=='look'"
                size="small"
                placeholder="请输入"
                class="smallw"
                v-model="form.dc_price"
              ></el-input
              >&nbsp;元
            </div>
          </div>
          <div class="item">
            <el-checkbox :disabled="type=='look'" v-model="form.jt_content" label="3">汽车</el-checkbox>
            <div>
              <el-input
                :disabled="type=='look'"
                size="small"
                placeholder="请输入"
                class="smallw"
                v-model="form.qc_price"
              ></el-input
              >&nbsp;元
            </div>
          </div>
        </div>
      </el-form-item>
      <el-form-item label="住宿" prop="zs_sprice">
        <el-input
          class="w300 mb16"
          placeholder="请输入"
          :value="form.zs_sprice"
          disabled
        ></el-input>
        <div>
          <!-- <div>
            <div class="flex mt8">
              <div class="myinputitem">
                <span class="label">单价/天</span>
                <el-input
                  :disabled="type=='look'"
                  v-model="form.hotel_unit_price"
                  size="small"
                  placeholder="请输入"
                  class="midw"
                ></el-input>
              </div>
              <div class="myinputitem">
                <span class="label">天数</span>
                <el-input
                  :disabled="type=='look'"
                  size="small"
                  v-model="form.hotel_day"
                  placeholder="请输入"
                  class="midw"
                ></el-input>
              </div>
            </div>
            <div class="flex  mt8">
              <div class="myinputitem">
                <span class="label">酒店标准</span>
                <el-input
                  :disabled="type=='look'"
                  v-model="form.hotel_standard"
                  size="small"
                  placeholder="请输入"
                  class="midw"
                ></el-input>
              </div>
              <div class="myinputitem">
                <span class="label">参考酒店</span>
                <el-input
                  :disabled="type=='look'"
                  v-model="form.hotel_reference"
                  size="small"
                  placeholder="请输入"
                  class="midw"
                ></el-input>
              </div>
            </div>
          </div> -->
          <!-- // 新加的 -->
          <div>
            <el-table
              class="small-table mb16"
              :data="form.hotel_detail"
              border
              style="width: 100%"
            >
              <el-table-column prop="hotel_day" label="第几天"> </el-table-column>
              <el-table-column prop="hotel_price" label="住宿价格（元）"> </el-table-column>
              <el-table-column prop="hotel_standard" label="酒店标准"> </el-table-column>
              <el-table-column prop="hotel_reference" label="参考酒店"> </el-table-column>
              <el-table-column label="操作" v-if="type!='look'">
                <template slot-scope="scope" >
                  <el-button
                    type="text"
                    @click="openDlg2(scope.row, scope.$index)"
                    ><i class="iconfont icon-edit"></i>编辑</el-button
                  >
                  <el-button type="text" @click="del2(scope.$index)"
                    ><i class="iconfont icon-del"></i>删除</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
            <div>
              <el-button v-if="type!='look'" type="primary" size="medium" @click="openDlg2('')"
                ><i class="iconfont icon-plus"></i>添加</el-button
              >
            </div>
          </div>
        </div>
      </el-form-item>
      <el-form-item label="景点" prop="jd_sprice">
        <el-input
          class="mb16 w300"
          placeholder="请输入"
          :value="form.jd_sprice"
          disabled
        ></el-input>
        <div>
          <el-table
            class="small-table mb16"
            :data="form.jd_content"
            border
            style="width: 100%"
          >
            <el-table-column prop="jd_name" label="景点名称"> </el-table-column>
            <el-table-column prop="jd_price" label="费用/人"> </el-table-column>
            <el-table-column prop="remark" label="备注"> </el-table-column>
            <el-table-column label="操作" v-if="type!='look'">
              <template slot-scope="scope" >
                <el-button
                  type="text"
                  @click="openDlg('jd', scope.row, scope.$index)"
                  ><i class="iconfont icon-edit"></i>编辑</el-button
                >
                <el-button type="text" @click="del('jd', scope.$index)"
                  ><i class="iconfont icon-del"></i>删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
          <div>
            <el-button v-if="type!='look'" type="primary" size="medium" @click="openDlg('jd')"
              ><i class="iconfont icon-plus"></i>添加</el-button
            >
          </div>
        </div>
      </el-form-item>
      <el-form-item label="吃" prop="sp_sprice">
        <el-input
          class="w300"
          placeholder="请输入"
          :value="form.sp_sprice"
          disabled
        ></el-input>
        <span class="ml16"
          >{{ form.zc_count||'-' }}个早餐 {{ form.wc_count||'-' }}个正餐</span
        >
        <div>
          <div>
            <div class="flex mt8">
              <div class="myinputitem">
                <span class="label">早餐价格</span>
                <el-input
                  :disabled="type=='look'"
                  size="small"
                  v-model="form.zc_price"
                  placeholder="请输入"
                  class="midw"
                ></el-input>
              </div>
              <div class="myinputitem">
                <span class="label">早餐数量</span>
                <el-input
                  :disabled="type=='look'"
                  size="small"
                  v-model="form.zc_count"
                  placeholder="请输入"
                  class="midw"
                ></el-input>
              </div>
            </div>
            <div class="flex  mt8">
              <div class="myinputitem">
                <span class="label">正餐价格</span>
                <el-input
                  :disabled="type=='look'"
                  size="small"
                  v-model="form.wc_price"
                  placeholder="请输入"
                  class="midw"
                ></el-input>
              </div>
              <div class="myinputitem">
                <span class="label">正餐数量</span>
                <el-input
                  :disabled="type=='look'"
                  size="small"
                  v-model="form.wc_count"
                  placeholder="请输入"
                  class="midw"
                ></el-input>
              </div>
            </div>
          </div>
        </div>
      </el-form-item>

      <el-form-item label="其他">
        <el-input
          class="mb16 w300"
          placeholder="请输入"
          :value="form.other_sprice"
          disabled
        ></el-input>
        <div>
          <el-table
            class="small-table mb16"
            :data="form.other_content"
            border
            style="width: 100%"
          >
            <el-table-column prop="other_name" label="名称"> </el-table-column>
            <el-table-column prop="other_price" label="费用/人">
            </el-table-column>
            <el-table-column prop="remark" label="备注"> </el-table-column>
            <el-table-column label="操作" v-if="type!='look'">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  @click="openDlg('other', scope.row, scope.$index)"
                  ><i class="iconfont icon-edit"></i>编辑</el-button
                >
                <el-button type="text" @click="del('other', scope.$index)"
                  ><i class="iconfont icon-del"></i>删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
          <div>
            <el-button v-if="type!='look'" type="primary" size="medium" @click="openDlg('other')"
              ><i class="iconfont icon-plus"></i>添加</el-button
            >
          </div>
        </div>
      </el-form-item>

      <el-form-item label="保险类型" prop="insuranceids">
        <div class="tip">
          如需新增保险类型，可在<el-button type="text" @click="goset">线路设置</el-button
          >中填写保险全局设置
        </div>
        <div>
          <el-checkbox-group v-model="form.insuranceids" :disabled="type=='look'">
            <el-checkbox
              v-for="item in insuranceList"
              :key="item.insurance_id"
              :label="item.insurance_id"
              >{{ item.insurance_name }}</el-checkbox
            >
          </el-checkbox-group>
        </div>
      </el-form-item>

      <el-form-item label="搭配产品">
        <el-radio-group :disabled="type=='look'"  v-model="form.is_append">
          <el-radio v-for="(item, key) in appendList" :key="key" :label="key">{{
            item
          }}</el-radio>
        </el-radio-group>
        <div v-show="form.is_append == 1">
          <el-table
            class="small-table mb16"
            :data="form.append_content"
            border
            style="width: 100%"
          >
            <el-table-column prop="dp_name" label="名称"> </el-table-column>
            <el-table-column prop="dp_price" label="费用/人"> </el-table-column>
            <el-table-column prop="remark" label="备注"> </el-table-column>
            <el-table-column label="操作" v-if="type!='look'">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  @click="openDlg('append', scope.row, scope.$index)"
                  ><i class="iconfont icon-edit"></i>编辑</el-button
                >
                <el-button type="text" @click="del('append', scope.$index)"
                  ><i class="iconfont icon-del"></i>删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
          <div >
            <el-button v-if="type!='look'" type="primary" size="medium" @click="openDlg('append')"
              ><i class="iconfont icon-plus"></i>添加</el-button
            >
          </div>
        </div>
      </el-form-item>
    </el-form>
    
    <!-- // 添加编辑 -->
    <el-dialog :title="dialogObj.title" :visible.sync="dialogFormVisible">
      <el-form
        ref="addform"
        :model="addform"
        :rules="addrules"
        label-width="120px"
      >
        <el-form-item label="名称" prop="name">
          <el-input placeholder="请输入" v-model="addform.name"></el-input>
        </el-form-item>
        <el-form-item label="费用/人" prop="fee">
          <el-input placeholder="请输入" v-model="addform.fee"></el-input>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input
            type="textarea"
            placeholder="请输入"
            :rows="4"
            v-model="addform.remark"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="doAction">确 定</el-button>
      </div>
    </el-dialog>
    <!-- // 添加编辑 -->
    <el-dialog :title="zhusuDialogTitle" :visible.sync="zhusuDialogFormVisible">
      <el-form
        ref="zhusuform"
        :model="zhusuform"
        :rules="zhusurules"
        label-width="130px"
      >
        <el-form-item label="第几天" prop="hotel_day">
          <el-input placeholder="请输入" :disabled="true" v-model="zhusuform.hotel_day"></el-input>
        </el-form-item>
        <el-form-item label="住宿价格（元）" prop="hotel_price">
          <el-input placeholder="请输入" v-model="zhusuform.hotel_price"></el-input>
        </el-form-item>
        <el-form-item label="酒店标准">
          <el-input placeholder="请输入" v-model="zhusuform.hotel_standard"></el-input>
        </el-form-item>
        <el-form-item label="参考酒店">
          <el-input placeholder="请输入" v-model="zhusuform.hotel_reference"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="zhusuDialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="addZhusu">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import upimg from 'components/upimg/upimg';
import { serachArea } from 'api/lineManagement/lineCommodity';
import { getSupplierAll } from 'api/supplierMg/supplierInfoAPI';
import { getSeriesAll } from 'api/lineManagement/seriesMgAPI';
import { getLablePageAll } from 'api/lineManagement/tagMgAPI';
import { line_status } from 'common/config/constConfig';
import { getInsuranceAll } from 'api/lineManagement/lineGlobalSettingAPI';
import { deepClone } from 'common/js/util';
export default {
  components: {
    upimg
  },
  props: ['type'],
  watch: {
    jtfee: {
      handler: function (val) {
        this.form.jt_sprice = val;
      },
      immediate: true
    },
    zhushu: {
      handler: function (val) {
        this.form.zs_sprice = val;
      },
      immediate: true
    },
    jdfee: {
      handler: function (val) {
        this.form.jd_sprice = val;
      },
      immediate: true
    },
    spfee: {
      handler: function (val) {
        this.form.sp_sprice = val;
      },
      immediate: true
    },
    otherfee: {
      handler: function (val) {
        this.form.other_sprice = val;
      },
      immediate: true
    },
    chengrenfee: {
      handler: function (val) {
        this.form.cb_price = val;
      },
      immediate: true
    },
    haizifee: {
      handler: function (val) {
        this.form.child_cb_price = val;
      },
      immediate: true
    },
    // jtfee(val) {
    // },
    // zhushu(val) {
    //   console.log(val, '住宿价格？')
    //   this.form.zs_sprice = val;
    // },
    // jdfee(val) {
    //   this.form.jd_sprice = val
    // },
    // spfee(val) {
    //   this.form.sp_sprice = val
    // },
    // otherfee(val) {
    //   this.form.other_sprice = val
    // },
    // chengrenfee(val) {
    //   this.form.cb_price = val
    // },
    // haizifee(val) {
    //   this.form.child_cb_price = val
    // }
  },
  computed: {
    zhusuDialogTitle() {
      if(this.dlgisEdit2) {
        return '编辑住宿'
      }
      return '添加住宿'
    },
    jtfee() {
      let num = 0;
      if (this.form.jt_content.indexOf('1') > -1 && this.form.fj_price) {
        num += this.form.fj_price * 100;
      }
      if (this.form.jt_content.indexOf('2') > -1 && this.form.dc_price) {
        num += this.form.dc_price * 100;
      }
      if (this.form.jt_content.indexOf('3') > -1 && this.form.qc_price) {
        num += this.form.qc_price * 100;
      }
      return num / 100;
    },
    zhushu() {
      let num = 0;
      if(this.form.hotel_detail.length) {
        console.log(this.form.hotel_detail, 'xx')
        this.form.hotel_detail.forEach(item => {
          num += item.hotel_price * 100
          console.log(num, '--')
        })
      }
      return num / 100
      // if (this.form.hotel_unit_price && this.form.hotel_day) {
      //   num += this.form.hotel_unit_price * this.form.hotel_day;
      // }
      // return num;
    },
    jdfee() {
      let num = 0;
      if(this.form.jd_content.length) {
        this.form.jd_content.forEach(item => {
          num += item.jd_price * 100
        })
      }
      return num / 100
    },
    spfee() {
      let num = 0;
      if(this.form.zc_price && this.form.zc_count) {
        num += this.form.zc_price * this.form.zc_count
      }
      if(this.form.wc_price && this.form.wc_count) {
        num += this.form.wc_price * this.form.wc_count
      }
      return num
    },
    otherfee() {
      let num = 0;
      if(this.form.other_content.length) {
        this.form.other_content.forEach(item => {
          num += item.other_price * 100
        })
      }
      return num / 100
    },
    chengrenfee() {
      let num = 0;
      if(this.jtfee) {
        num += this.jtfee * 100
      }
      if(this.zhushu) {
        num += this.zhushu * 100
      }
      if(this.jdfee) {
        num += this.jdfee * 100
      }
      if(this.jtfee) {
        num += this.spfee * 100
      }
      if(this.otherfee) {
        num += this.otherfee * 100
      }
      return num / 100
    },
    haizifee() {
      let num = 0;
      if(this.jtfee) {
        num += this.jtfee * 100
      }
      if(this.spfee) {
        num += this.spfee * 100
      }
      if(this.otherfee) {
        num += this.otherfee * 100
      }
      return num / 100
    },
    dialogObj() {
      let obj;
      if (this.dlgisEdit) {
        obj = {
          jd: {
            title: '编辑景点'
          },
          other: {
            title: '编辑其他'
          },
          append: {
            title: '编辑搭配'
          }
        };
      } else {
        obj = {
          jd: {
            title: '添加景点'
          },
          other: {
            title: '添加其他'
          },
          append: {
            title: '添加搭配'
          }
        };
      }

      return obj[this.dlgMode];
    }
  },
  data() {
    return {
      dlgMode: 'jd',
      dlgisEdit: false,
      dlgisEdit2: false,
      zhusuDialogFormVisible: false,
      appendList: {
        1: '有',
        0: '无'
      },
      dialogFormVisible: false,
      zhusuform: {},
      addform: {},
      lineStatus: line_status,
      form: {
        jt_sprice: '',
        zs_sprice: '',
        commodity_img: [],
        start_address: [],
        lable_ids: [],
        hotel_detail: [], //住宿
        jt_content: [], // 交通
        other_content: [], // 其他
        insuranceids: [], // 保险
        append_content: [], // 搭配产品
        jd_content: [] // 景点
      },
      loading: false,
      imgs: [],
      startAdress: [],
      seriesList: [],
      tagList: [],
      supplierList: [],
      insuranceList: [],
      zhusurules: {
        hotel_day: [{ required: true, message: '请输入天数', trigger: 'blur' }],
        hotel_price: [{ required: true, message: '请输入价格', trigger: 'blur' }]
      },
      rules: {
        supplier_id: [
          { required: true, message: '请选择供应商', trigger: 'change' }
        ],
        start_address: [
          { required: true, message: '请选择出发地', trigger: 'change' }
        ],
        series_id: [
          { required: true, message: '请选择系列', trigger: 'change' }
        ],
        commodity_name: [
          { required: true, message: '请输入线路名称', trigger: 'blur' }
        ],
        commodity_img: [
          { required: true, message: '请上传轮播图', trigger: 'change' }
        ],
        commodity_release: [
          { required: true, message: '请选择状态', trigger: 'change' }
        ],
        lable_ids: [
          { required: true, message: '请选择标签', trigger: 'change' }
        ],
        pricing: [
          { required: true, message: '请输入产品显示售价', trigger: 'blur' }
        ],
        cb_price: [
          { required: true, message: '价格不能为空' }
        ],
        child_cb_price: [
          { required: true, message: '价格不能为空'}
        ],
        jt_sprice: [
          { required: true, message: '价格不能为空'}
        ],
        zs_sprice: [
          { required: true, message: '价格不能为空' }
        ],
        jd_sprice: [
          { required: true, message: '景点不能为空' }
        ]
        // sp_sprice: [
        //   { required: true, message: '景点不能为空', trigger: 'change' }
        // ]
      },
      addrules: {
        name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
        fee: [{ required: true, message: '请输入费用', trigger: 'blur' }]
      },
    };
  },
  methods: {
    getChengben() {
      return {
        costCr: this.form.cb_price || 0,
        costEt: this.form.child_cb_price || 0,
        costZS: this.form.zs_sprice || 0,
      }
    },
    goset() {
      window.open('/home/lineGlobalSetting')
    },
    del(index) {
      this.form[this.dlgMode + '_content'].splice(index, 1);
    },
    async addZhusu() {
      // xxx
      await this.$refs.zhusuform.validate();
      if(this.dlgisEdit2) {
        this.form.hotel_detail.splice(this.editIndex, 1, this.zhusuform)
      }else{
        this.form.hotel_detail.push(this.zhusuform)
      }
      this.zhusuDialogFormVisible = false;
    },
    async doAction() {
      //
      await this.$refs.addform.validate();
      let obj = {
        remark: this.addform.remark
      };
      if (this.dlgMode === 'append') {
        obj.dp_name = this.addform.name;
        obj.dp_price = this.addform.fee;
      } else {
        obj[this.dlgMode + '_name'] = this.addform.name;
        obj[this.dlgMode + '_price'] = this.addform.fee;
      }
      if (this.dlgisEdit) {
        let oldObj = [...this.form[this.dlgMode + '_content']];
        oldObj[this.editIndex] = obj;
        this.form[this.dlgMode + '_content'] = oldObj;
      } else {
        this.form[this.dlgMode + '_content'].push(obj);
      }
      this.dialogFormVisible = false;
    },
    openDlg2(row, index) {
      this.zhusuform = {hotel_day: 1};
      this.zhusuDialogFormVisible = true;
      this.dlgisEdit2 = false;
      let len = this.form.hotel_detail.length
      if(len>0) {
        this.zhusuform.hotel_day = this.form.hotel_detail[len-1].hotel_day + 1
      }
      if (row) {
        this.editIndex = index;
        this.dlgisEdit2 = true;
        let obj = {...row};
        this.zhusuform = obj;
      }
    },
    del2(index) {
      this.form.hotel_detail.splice(index, 1)
    },
    openDlg(type, row, index) {
      this.dlgMode = type;
      this.addform = {};
      this.dialogFormVisible = true;
      this.dlgisEdit = false;
      if (row) {
        this.editIndex = index;
        this.dlgisEdit = true;
        let obj = {};
        obj.remark = row.remark;
        if (type === 'append') {
          obj.name = row.dp_name;
          obj.fee = row.dp_price;
        } else {
          obj.name = row[type + '_name'];
          obj.fee = row[type + '_price'];
        }
        this.addform = obj;
      }
    },
    setData(obj) {
      let newObj = deepClone(obj)
      delete newObj.reserveInfo
      delete newObj.featureInfo
      delete newObj.costInfo
      delete newObj.journeyInfo
      delete newObj.relevanceInfo
      delete newObj.repertoryArr
      newObj.hotel_detail = newObj.hotel_detail || []
      newObj.start_address = newObj.start_address ? newObj.start_address.split(',') : []
      newObj.commodity_img = newObj.commodity_img ? newObj.commodity_img.split(',') : []
      newObj.lable_ids = newObj.lable_ids ? newObj.lable_ids.split(',').map(item => parseInt(item)) : []
      newObj.jt_content = []
      if(newObj.fj_price!='0') {
        newObj.jt_content.push('1')
      }
      if(newObj.dc_price!='0') {
        newObj.jt_content.push('2')
      }
      if(newObj.qc_price!='0') {
        newObj.jt_content.push('3')
      }
      newObj.insuranceids = newObj.insuranceids ? newObj.insuranceids.split(',').map(item => parseInt(item)) : []
      newObj.commodity_release = ''+ (newObj.commodity_release ? newObj.commodity_release : '')
      newObj.is_append = ''+(newObj.is_append ? newObj.is_append : '')
      this.form = {...this.form, ...newObj}
      // console.log('来了', obj)
    },
    
    async getData(isValidate = true) {
      // try {
        if(isValidate) {
          await this.$refs.form.validate()
        }
        let data = {...this.form}
        if(data.supplier_id) {
          data.supplier_name = this.supplierList.find(item => item.supplier_id === data.supplier_id).supplier_name
        }
        if(data.series_id) {
          data.series_name = this.seriesList.find(item => item.series_id === data.series_id).series_name
        }
        data.start_address = data.start_address ? data.start_address.join(',') : ''
        data.commodity_img = data.commodity_img ? data.commodity_img.join(',') : ''
        let namearr = []

        if(data.lable_ids.length) {
          this.tagList.forEach(item => {
            if(data.lable_ids.indexOf(item.lable_id) > -1){
              namearr.push(item.lable_name)
            }
          })
          data.lable_ids = data.lable_ids.join(',')
          data.commodity_lable =  namearr.join(',')
        }else{
          data.lable_ids = ''
          data.commodity_lable =  ''
        }

        data.insuranceids = data.insuranceids ? data.insuranceids.join(',') : ''
        return data
      // } catch (error) {
      //   return false
      // }
      
    },
    // 搜锁地址
    async remoteMethod(val) {
      if(!val) return
      this.loading = true
      let res = await serachArea(val);
      this.loading = false
      this.startAdress = res.rData;
    },
    // 获取供应商列表
    async _getSupplierAll() {
      let res = await getSupplierAll();
      this.supplierList = res.rData;
    },
    // 获取系列列表
    async _getSeriesAll() {
      let res = await getSeriesAll();
      this.seriesList = res.rData;
    },
    // 获取全部标签
    async _getLablePageAll() {
      let res = await getLablePageAll();
      this.tagList = res.rData;
    },
    // 获取保险列表
    async _getInsuranceAll() {
      let res = await getInsuranceAll();
      this.insuranceList = res.rData;
    }
  },
  mounted() {
    this._getSupplierAll();
    this._getSeriesAll();
    this._getLablePageAll();
    this._getInsuranceAll();
  }
};
</script>

<style lang="scss" scoped>

.traffic-con {
  display: flex;
  .item {
    display: flex;
    margin-right: 30px;
    .el-checkbox {
      margin-right: 10px;
    }
  }
}
.myinputitem {
  display: flex;
  .label {
    width: 100px;
    text-align: right;
    padding-right: 10px;
    color: #606266;
  }
}
.smallw {
  width: 100px;
}
.w300 {
  width: 300px;
}
</style>
